import { createRouter, createWebHashHistory, createWebHistory } from 'vue-router'
import Home from "../views/Home.vue"
//路由的配置
const routes = [
    {
        path: '/',
        name: 'home',
        // redirect:'/find',  //重定向到find页面
        component: Home,
        meta: {title: '首页'}
    },
    {
        path: '/about',
        name: 'about',
        component: () => import('../views/About.vue'),
        meta: {title: '关于'}
    },
    {
        path: '/find',
        name: 'find',
        component: () => import('../views/Find.vue'),
        meta: { title: '发现音乐' },
        children: [
            {
                path: 'discover', //单页面应用 不需要添加 /
                name: 'discover',
                component: () => import('../views/mysong/Discover.vue'),
                meta: { title: '推荐音乐' },
                children: [
                    {
                        path: 'remtj',
                        name: 'remtj',
                        component: () => import('../views/mysong/tuijiam/RemTJ.vue'),

                    }
                ]
            },
            {
                path: 'toplist',
                name: 'toplist',
                component: () => import('../views/mysong/Toplist.vue'),
                meta: { title: '排行榜' }
            },
            {
                path: 'playlist',
                name: 'playlist',
                component: () => import('../views/mysong/Playlist.vue'),
                meta: { title: '排行榜' }
            }
        ]
    },
    {
        path: '/my',
        name: 'my',
        component: () => import('../views/My.vue'),
        meta: { title: '我的音乐' }
    }
    ,
    {
        path: '/friend',
        name: 'friend',
        component: () => import('../views/Friend.vue'),
        meta: { title: '关注' }
    }
    ,
    {
        path: '/parent',
        name: 'parent',
        component: () => import('../views/Parent.vue'),
      
    },
    {
        path: '/parent/:username',
        name: 'parent',
        component: () => import('../views/Parent.vue'),       
    }
    // },
    // {
    //     path: '/parent/:username',
    //     name: 'parent',
    //     component: () => import('../views/Parent.vue'),
       
    // }
]
//创建路由
const router = createRouter({
    history: createWebHashHistory(),  //hash模式 包含#号
    //history: createWebHistory(),
    routes
})
/**
 * 路由守卫 ： 全局守卫 组件守卫
 * to: d要跳转的路由对象 （路由目的地）
 * from: 从哪个路由跳转过来的 （路由来源）
 * next: 路由的控制参数 下一步要干什么  默认是true next(false) 原地不动
 */

// const islogin =true
// router.beforeEach((to, from, next) => { 
//     // console.log(to.path);
//     console.log(from);
//     if (to.path == '/my' && islogin == true) { 
//         alert('请先登录');
//         next(true);
//     }

// })
//导出路由
export default router